<?php
/**
 * ProjectName: Grapes.
 * Created by LemonZ.
 * FileName: Message.php
 * Date: 2019/2/14
 * Time: 14:51
 * Description:
 */

namespace app\admin\controller;


use app\common\controller\Admin;
use app\common\model\Message as MessageModel;
use app\common\model\MessageCenter as MessageCenterModel;
use think\facade\Request;

class Message extends Admin
{
    /**
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function index()
    {
        if(Request::isAjax()){
            $messageModel = new MessageModel();
            return $messageModel->tableData(input('param.'));
        }else{
            $messageCenterModel = new MessageCenterModel;
            $this->assign('tpl',$messageCenterModel->tpl);
            return $this->fetch('index');
        }
    }

    /**
     * @return array|mixed
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function del()
    {
        if(!input('?param.id')){
            return error_code(10003);
        }
        $id = input('param.id');
        $messageModel = new MessageModel();
        if($messageModel->where(['id'=>$id])->delete()){
            return [
                'status' => true,
                'data' => '',
                'msg' => '删除成功'
            ];
        }else{
            return [
                'status' => false,
                'data' => '',
                'msg' => '删除失败'
            ];
        }
    }
}